Skip to content

fix: make DependencyInfo.hashCode() consistent with equals() - #626

Open
elharo wants to merge 1 commit into
apache:masterfrom
elharo:fix-620-hashcode-contract
Open

fix: make DependencyInfo.hashCode() consistent with equals()#626
elharo wants to merge 1 commit into
apache:masterfrom
elharo:fix-620-hashcode-contract

Conversation

@elharo

@elharo elharo commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #620

equals() compares only the dependency field, but hashCode() incorrectly incorporated both dependency and targetFileName, violating the equals/hashCode contract.

Includes TDD: wrote failing test for hashCode consistency first, then applied the fix.

equals() compares only the 'dependency' field, but hashCode()
incorrectly incorporated both 'dependency' and 'targetFileName',
violating the equals/hashCode contract. Now hashCode() uses only
'dependency', matching equals().

Fixes apache#620

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the equals()/hashCode() contract for DependencyInfo by aligning hashCode() with the existing equals() semantics (dependency-only), and adds a dedicated unit test to prevent regressions.

Changes:

  • Update DependencyInfo.hashCode() to compute the hash from dependency only (matching equals()).
  • Add DependencyInfoTest covering dependency-only equality and hashCode consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main/java/org/apache/maven/plugins/war/util/DependencyInfo.java Makes hashCode() consistent with equals() by hashing only dependency.
src/test/java/org/apache/maven/plugins/war/util/DependencyInfoTest.java Adds regression tests for dependency-only equality and hashCode consistency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@elharo
elharo requested a review from khmarbaise July 4, 2026 14:51
@elharo
elharo requested a review from sparsick July 19, 2026 12:06
@elharo elharo added the bug Something isn't working label Jul 24, 2026
@elharo
elharo requested review from bdemers and desruisseaux July 24, 2026 11:16
@elharo
elharo requested a review from CrazyHZM July 31, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DependencyInfo.hashCode() violates equals/hashCode contract

2 participants